package org.brisling.sysman.service;

import java.util.List;

import org.brisling.authorize.shiro.ShiroSecurityService;
import org.brisling.base.domain.ListDomain;
import org.brisling.base.domain.RetDomain;
import org.brisling.common.ConstSysParam;
import org.brisling.sysman.domain.SysBugs;
import org.brisling.sysman.repository.BugRepo;
import org.brisling.sysman.service.base.BaseSysmanFlowService;
import org.brisling.workflow.domain.VOHistoric;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;


@RestController
@RequestMapping("/bug")
/**
 * 用戶后台服務service
 * @Author : jackson wang
 * @Date   : 2015年6月8日 下午4:18:01
 * @version: 1.0
 */
public class BugService extends BaseSysmanFlowService<SysBugs>{
	
			
	@SuppressWarnings("unused")
	@Autowired
	private BugRepo baseFlowRepo;	
	
	@Autowired
	private ShiroSecurityService shiroSecurityService;
	
	public BugService(){
		this.moduleName = ConstSysParam.MODULE_BUG;
		this.clazz = SysBugs.class;
	}
	
	/**
	 * 获取业务主页面 
	 * @return
	 */
	@RequestMapping("/mainPage.action")
	public ModelAndView getMainPage(){
		return getBizMainPage();
	}
	
	/**
	 * 获取业务编辑页面
	 * @return
	 */
	@RequestMapping("/editPage.action")
	public ModelAndView getEditPage(){
		return getBizEditPage();
	}
	
	/**
	 * 返回缺陷记录流程实例id的执行记录
	 * @param procInstId 流程实例id
	 * @return List<HistoricTaskInstance> 流程实例执行记录
	 */
	@RequestMapping("/flowHistorics.action")
	public List<VOHistoric> getHistoricByProcInstId(@RequestParam(value="flowInstId",required=false) String procInstId){
		return super.getHistoricByProcInstId(procInstId);
	}
	
	/**
	 * 返回缺陷记录流程实例id的执行记录
	 * @param procInstId 流程实例id
	 * @return List<HistoricTaskInstance> 流程实例执行记录
	 */
	@RequestMapping("/flowHistoricsListDomain.action")
	public ListDomain<VOHistoric> getBugHistoricListDomainByProcInstId(@RequestParam(value="flowInstId",required=false) String procInstId){
		return super.getHistoricListDomainByProcInstId(procInstId);
	}
	/**
	 * 分页查询用户列表页面
	 * @param deptid
	 * @param page
	 * @param rows
	 * @param sort
	 * @return
	 */
	@RequestMapping("/flowListDomain.action")
	public ListDomain<SysBugs> getListDomain(
			@RequestParam(value="page",required=false) Integer page,
			@RequestParam(value="rows",required=false) Integer rows,
			@RequestParam(value="sort",required=false) String sort,
			@RequestParam(value="fullBizcode",required=false) String fullBizcode){
		
		
			return super.getListDomain(page, rows, sort, fullBizcode);
			
	}
	
	
	/**
	 * 分页查询用户列表页面
	 * @param deptid
	 * @param page
	 * @param rows
	 * @param sort
	 * @return
	 */
	@RequestMapping("/flowList.action")
	public List<SysBugs> getPagedFlowRows(
			@RequestParam(value="page",required=false) Integer page,
			@RequestParam(value="rows",required=false) Integer rows,
			@RequestParam(value="sort",required=false) String sort,			
			@RequestParam(value="fullBizcode",required=false) String fullBizcode
			){		
		
		return super.getPagedFlowRows(page, rows, sort, fullBizcode);			
	}
	
	@RequestMapping("/flowDel.action")
	public RetDomain delRow(@RequestParam(value="id",required=false) Long id){
		RetDomain domain = new RetDomain();
		if(super.deleteTask(id, null)){
			domain.setSuccessMsg("200");
			return domain;
		}else{
			domain.setErrorMsg("500");
			return domain;
		}		
	}
	
	
	/**
	 * 保存缺陷记录
	 * @param id
	 */
	@RequestMapping("/flowSave.action")
	public SysBugs save(@RequestBody String body){
		SysBugs obj = bodyToObj(body, SysBugs.class);
		
		return super.saveFlowEntity(shiroSecurityService.getCurrentUserid().toString(),obj);
	}
	
	/**
	 * 签收记录
	 * @param flowInstId	流程实例id
	 * @param flowTaskId	流程节点id
	 * @param signInfo		签收信息
	 * @param body
	 * @return
	 */
	@RequestMapping("/flowSign.action")
	public String saveBugSingInfo(@RequestParam(value="flowInstId",required=false) String flowInstId,
			@RequestParam(value="flowTaskId",required=false) String flowTaskId,
			@RequestParam(value="signInfo",required=false) String signInfo,
			@RequestBody String body){
			
		return super.saveSignInfo(shiroSecurityService.getCurrentUserid().toString(), flowInstId,flowTaskId, signInfo);
	}
	
	/**
	 * 流程执行
	 * @param flowInstId	流程实例id
	 * @param flowTaskId	流程任务节点id
	 * @param signInfo		签收信息
	 * @param body
	 * @return
	 */
	@RequestMapping("/flowTaskComplete.action")
	public String saveBugTaskComplete(
			@RequestParam(value="flowInstId",required=false) String flowInstId,
			@RequestParam(value="flowTaskId",required=false) String flowTaskId,
			@RequestParam(value="signInfo",required=false) String signInfo,
			@RequestBody String body){
		
		return super.completeTaskAndCandidateById(shiroSecurityService.getCurrentUserid().toString(),flowInstId, signInfo);
		
	}
	
	
	
	
}
